export default function nestTokens(tokens) {
    const sections = [];
    const nestedTokens = [];
    let collection = nestedTokens;

    tokens.forEach(token => {
        const type = token[0];

        switch (type) {
            case '#':
                collection.push(token);
                sections.push(token);
                collection = token[2] = [];
                break;
            case '/':
                sections.pop();
                collection = sections.length !== 0
                    ? sections[sections.length - 1][2]
                    : nestedTokens;
                break;
            default:
                collection.push(token);
        }
    });

    return nestedTokens;
};